using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public static class GameObjectExtension
{
    /// <summary>
    /// 判断对象是否在屏幕内 如果物体未激活则一直返回false
    /// </summary>
    /// <param name="obj"></param>
    /// <returns></returns>
    public static bool IsGameObjectOnScreen(this GameObject obj)
    {
        if (!obj.activeSelf) return false;
        Vector3 screenPoint = Camera.main.WorldToViewportPoint(obj.transform.position);
        return screenPoint.z > 0 && screenPoint.x > 0 && screenPoint.x < 1 && screenPoint.y > 0 && screenPoint.y < 1;
    }
}
